package com.news;

import android.app.Activity;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;

class FlingGesture extends SimpleOnGestureListener {

    private Activity a               = null;

    final int        horizontalRange = 10;

    final int        verticalRange   = 50;

    final int        GESTURE_LEFT    = 1;

    final int        GESTURE_RIGHT   = 2;

    final int        GESTURE_INVALID = 0;

    public FlingGesture(Activity activity) {
        a = activity;
    }

    public FlingGesture() {

    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        Toast.makeText(a.getApplicationContext(), "FLING", Toast.LENGTH_SHORT)
                .show();
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        if (distanceY < horizontalRange && distanceX > verticalRange) {
            android.webkit.WebView webView = (android.webkit.WebView) a
                    .getWindow().getDecorView().findViewById(R.id.Webview);
            webView.goBack();
        } else if (distanceY < horizontalRange && distanceX < -verticalRange) {
            android.webkit.WebView webView = (android.webkit.WebView) a
                    .getWindow().getDecorView().findViewById(R.id.Webview);
            webView.goForward();
        }
        return false;
    }

    @Override
    public boolean onDown(MotionEvent me) {
        return true;
    }
}